package day0726API;

public class Test4 {
    public static void main(String[] args) {
        //2.将线程任务对象Task传入到Thread对象中
        Task  task=new Task();
        Thread t1=new Thread(task);
        //3.调用线程Thread t1的start();
        t1.start();

        Thread t2=new Thread(task);
        //3.调用线程Thread t1的start();
        t2.start();
    }
}


//1.用一个类实现Runnable接口并实现run方法(作为线程要运行的代码)
class Task  implements  Runnable{
    public void run() {//实现Runnable接口并实现run方法
        while(true){
            try {
                Thread.sleep(900);
                Thread thisThread=Thread.currentThread();
                System.out.println(thisThread.getName()+"卖包子了...");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}